<?php
include_once "header.php";


if(isset($_GET["id"])){

	$daftar_sm = new Daftar_surat_masuk();
	$sm = $daftar_sm->getById($_GET["id"]);

} 

$cek_field="";

if (ISSET($_POST["ubah_sm"])){

	if($_POST['nomor']=="" || $_POST['tgl']=="" || $_POST['hal']=="" || $_POST['sifat']=="" || $_POST['asal']==""){
		
		$cek_field = "Peringatan: Silahkan isikan seluruh data yang tersedia.";
	
	} else {
		$daftar_surat_masuk = new Daftar_surat_masuk();
		$surat_masuk = new Surat_masuk();
		$surat_masuk->setId($_POST['id']);
		$surat_masuk->setNomor($_POST['nomor']);
		$surat_masuk->setTgl($_POST['tgl']);
		$surat_masuk->setHal($_POST['hal']);
		$surat_masuk->setSifat($_POST['sifat']);
		$surat_masuk->setLampiran($_POST['lampiran']);
		$surat_masuk->setAsal($_POST['asal']);
		//var_dump($surat_masuk);
		$daftar_surat_masuk->edit($surat_masuk);
		
		header("Location:detil_sm.php?id=".$surat_masuk->getId()."");
		}
	
}
?>

<div id="container">
	<div id="errorcont">
		<?php echo $cek_field;?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Surat Masuk > Detil > Ubah
			</div>
			<div id="body">
			<br>
			<form method="post" action="ubah_sm.php?id=<?php echo $_GET["id"]; ?>">
			<input type="hidden" name="ubah_sm">
			<input type="hidden" name="id" value="<?php echo $_GET["id"]; ?>">
			<table border=0 cellspacing=0 cellpadding=4 width=100%>	
				<tr>
					<td>Nomor</td>
					<td>:</td>
					<td><input type="text" name="nomor" value="<?php echo $sm->getNomor(); ?>" size=64 ></td>
				</tr>
				<tr>				
					<td>Tanggal</td>
					<td>:</td>
					<td><input type="text" name="tgl" id="tgl" value="<?php echo $sm->getTgl(); ?>" ></td>
				</tr>
				<tr>	
					<td>Hal</td>
					<td>:</td>
					<td><input type="text" name="hal" value="<?php echo $sm->getHal(); ?>" size=100></td>
				</tr>
				<tr>	
					<td>Sifat</td>
					<td>:</td>
					<td> <?php
					$daftar_sifat = new Daftar_sifat_surat();
					$sifat = $daftar_sifat->getAll();
					?>
					<select name="sifat">
					<?php
						foreach($sifat as $Sifat){
							if($sm->getSifat()== $Sifat->getId()){
								echo "<option value=".$Sifat->getId()." selected>".$Sifat->getSifat()."</option>";
							} else{
								echo "<option value=".$Sifat->getId().">".$Sifat->getSifat()."</option>";
							}
						}
					?>
					
					</select>
					</td>
				</tr>
				<tr>	
					<td>Lampiran</td>
					<td>:</td>
					<td><input name="lampiran" value="<?php echo $sm->getLampiran(); ?>"></td>
				</tr>
				<tr>	
					<td>Asal</td>
					<td>:</td>
					<td><input type="text" name="asal" value="<?php echo $sm->getAsal(); ?>" size=64 ></td>
				</tr>
					<td></td>
					<td></td>
					<td align="right"><input type="submit" value="Simpan"> <input type="button" value="Batal" onClick="window.location.href='detil_sm.php?id=<?php echo $_GET["id"]; ?>'"> </td>
				</tr>		
			</table>
			</form>
			
						
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	$(function() { 
	$("#tgl").datepicker({dateFormat: "yy-mm-dd",
											buttonImage:'jquery/css/images/calendar.gif',
											buttonImageOnly: true,
											showOn: 'button'
	}); 
	});
</script>
